//
//  FunctionView.m
//  
//
//  Created by chris on 15/12/26.
//
//

#import "FunctionView.h"
#import "MyButton.h"
#import "SDWebImageCompat.h"
#import "UIView+Extension.h"

@implementation FunctionView {
    CGRect _frame;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        _frame = frame;
    }
    return self;
}

- (void) drawMySubvies {
    [self removeAllSubViews];
    UIImageView * horLine = [[UIImageView alloc]initWithFrame:CGRectMake(0, _frame.size.height*1/3-0.5, _frame.size.width, 1)];
    horLine.backgroundColor = [UIColor colorWithRed:0.89 green:0.89 blue:0.89 alpha:1];
    [self addSubview:horLine];

    UIImageView * horLine1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, _frame.size.height*2/3-0.5, _frame.size.width, 1)];
    horLine1.backgroundColor = horLine.backgroundColor;
    [self addSubview:horLine1];

    UIImageView * verLine = [[UIImageView alloc]initWithFrame:CGRectMake(_frame.size.width/2-0.5,0, 1, _frame.size.height)];
    verLine.backgroundColor = [UIColor colorWithRed:0.89 green:0.89 blue:0.89 alpha:1];
    [self addSubview:verLine];



    NSArray * titles = @[
            [NSString stringWithFormat:@"门店签约(%li)",(long)_pendingWebstieNum],
            [NSString stringWithFormat:@"工单处理(%li)",(long)_pendingOrderNum],
            @"号池管理",
            @"消息管理",
            [NSString stringWithFormat:@"后台业务管理(%li)",(long)_pendingBlackNum],
    ];
    NSArray<NSString*> * icons =  @[@"mdsh",       @"gdcl",  @"hcgl",    @"xiaoxi",   @"xiaoxi"];
    int index = 0;
    int rows = 3;
    int cols = 2;
    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < cols; j++)
        {
            if (index > icons.count-1) {
                return;
            }
            MyButton * button = [[MyButton alloc]initWithFrame:CGRectMake(20+((DEF_SCREEN_WIDTH-1)/cols)*j, 20+((_frame.size.height-1)/rows)*i, DEF_SCREEN_WIDTH/cols-41, _frame.size.height/rows-41)];
            if (DEF_SCREEN_HEIGHT <= 568)
            {
                button.frame = CGRectMake(20+((DEF_SCREEN_WIDTH-1)/cols)*j, 10+((_frame.size.height-1)/rows)*i, DEF_SCREEN_WIDTH/cols-41, _frame.size.height/rows-21);
            }
            button.tag = 100+index;
            button.titleLa.text = titles[index];
            [button setUiImage:[UIImage imageNamed:icons[index]]];
            button.multipleTouchEnabled  =  YES;
            button.userInteractionEnabled = YES;
            SEL clickSelector = @selector(click:);
            [button addTarget:self action:clickSelector forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:button];
            index++;
        }

    }
}

- (void)setPendingOrderNum:(NSInteger)pendingOrderNum {
    _pendingOrderNum = pendingOrderNum;
}




#pragma mark-点击事件
- (void)click:(UIButton *)btn
{
    int myIndex = btn.tag%100;
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickWithIndex:)])
    {
        [self.delegate clickWithIndex:myIndex];
    }
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
